<template>
    <div
        :class="`btn btn-${type} ${disabled || loading ? 'btn-disabled' : ''}`"
        @click="doClick"
    >
        <i
            v-show="loading"
            class="iconfont icon-loading"
        ></i>
        <slot></slot>
    </div>
</template>

<script>
/**
 * 按钮
 */
export default {
    name: 'Button',
    props: {
        // 是否块级按钮
        // block: {type: Boolean, default: false},
        // 按钮类型（其实就是决定主题色，目前暂未定义其他色，后期你来补充）
        type: {
            type: String,
            validator(value) {
                return ['primary'].indexOf(value) > -1;
            },
            default: 'primary',
        },
        // 是否禁止
        disabled: { type: Boolean, default: false },
        // 是否读取状态
        loading: { type: Boolean, default: false },
    },
    methods: {
        doClick(e) {
            if (this.disabled || this.loading) {
                return;
            }
            this.$emit('click', e);
        },
    },
};
</script>

<style scoped>
.btn {
    flex: 1;
    width: 100%;
    cursor: pointer;
    border-radius: 2px;
    font-size: 16px;
    line-height: 42px;
    text-align: center;
}

.btn:active {
    background-color: #005fc8;
}

.btn > .iconfont {
    margin-right: 10px;
}

.btn-block {
    display: block;
}

.btn-primary {
    color: #fff;
    background-color: #1890ff;
}

.btn-disabled,
.btn-disabled:active {
    background: #f2f2f2;
    color: #b9b9b9;
}
</style>
